package com.imay.live.activity.recharge;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.imay.live.activity.BaseRequestActivity;
import com.imay.live.adapter.DiscoveryIndicatorAdapter;
import com.imay.live.fragment.discovery.MyFragmentPagerAdapter;
import com.imay.live.fragment.pay.GetthistoryFrament;
import com.imay.live.fragment.pay.PuthistoryFrament;
import com.imay.live.view.indicator.Indicator;
import com.imay.live.view.indicator.ScrollIndicatorView;
import com.imay.live.view.indicator.slidebar.ColorBar;
import com.imay.live.R;

import java.util.ArrayList;

/**
 * Created by lzx on 2017/04/17 0017.
 * 充值记录
 */

public class MyRechargeHistoryActivity extends BaseRequestActivity {
    ViewPager mViewPager;
    ArrayList<Fragment> fragments = new ArrayList<Fragment>();
    private ScrollIndicatorView mIndicatorView;
    static String INDEX = "index";

    public static void start(Context context, int index) {
        Intent starter = new Intent(context, MyRechargeHistoryActivity.class);
        starter.putExtra(INDEX, index);
        context.startActivity(starter);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.myrechargelayout;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        setTitle(getResources().getString(R.string.my_recharge_history));
        int index = getIntent().getIntExtra(INDEX, 0);
        mViewPager = $(R.id.viewpager);
        mIndicatorView = $(R.id.siv_history);
//        ColorBar colorBar = new ColorBar(this, getResources().getColor(R.color.indicator_bar_select), (int) getResources().getDimension(R.dimen.size_3dp));
        ColorBar colorBar = new ColorBar(this, getResources().getColor(R.color.text_8d), (int) getResources().getDimension(R.dimen.size_3dp));
        colorBar.setWidth((int) getResources().getDimension(R.dimen.tab_ind_w));
        mIndicatorView.setScrollBar(colorBar);
        fragments.add(PuthistoryFrament.newInstance());
        fragments.add(GetthistoryFrament.newInstance());
        mViewPager.setOffscreenPageLimit(1);
        String[] tabTitles = new String[]{getString(R.string.put_history), getString(R.string.get_history)};
        MyFragmentPagerAdapter adapter = new MyFragmentPagerAdapter(getSupportFragmentManager(), fragments, tabTitles);
        mViewPager.setAdapter(adapter);

        DiscoveryIndicatorAdapter mIndicatorAdapter = new DiscoveryIndicatorAdapter(this, getSupportFragmentManager(), tabTitles,R.layout.view_indicator_rechargehis);
        mIndicatorView.setAdapter(mIndicatorAdapter.getIndicatorAdapter());

        mIndicatorView.setOnItemSelectListener(new Indicator.OnItemSelectedListener() {
            @Override
            public void onItemSelected(View selectItemView, int select, int preSelect) {

                mViewPager.setCurrentItem(select);
            }
        });
        mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i2) {

            }

            @Override
            public void onPageSelected(int i) {
                mIndicatorView.setCurrentItem(i);
            }

            @Override
            public void onPageScrollStateChanged(int i) {

            }
        });
        if (index > 1) {
            mViewPager.setCurrentItem(0);
        } else {
            mViewPager.setCurrentItem(index);
        }

    }
}
